

export default function () {

  const isOptionP = (option) => {
    if (!option?.q) return ''
    const qrUrl = decodeURIComponent(option.q)
    let jsonUrl = GetWxUrlParam(qrUrl)
    return jsonUrl
  }

  //解析链接地址
  const GetWxUrlParam = (url) => {
    let theRequest = {};
    if (url.indexOf("#") != -1) {
      const str = url.split("#")[1];
      const str_s = str.split("&");
      for (let i = 0; i < str_s.length; i++) {
        theRequest[str_s[i].split("=")[0]] = decodeURI(str_s[i].split("=")[1]);
      }
    } else if (url.indexOf("?") != -1) {
      const str = url.split("?")[1];
      const str_s = str.split("&");
      for (let i = 0; i < str_s.length; i++) {
        theRequest[str_s[i].split("=")[0]] = decodeURI(str_s[i].split("=")[1]);
      }
    }
    return theRequest;
  }

  return {
    isOptionP,
    GetWxUrlParam
  }
}
